role information
helloz 4/3/2024 Unity3d
Other characters enter and exit the game notification & get user object
eventType 事件类型:
1164 type conversion: int to string
eventType | parameter | describe |
---|---|---|
'MsgEventType.JOIN_OTHER_ROOM' | List | New user joins, data id list |
‘MsgEventType.OUT_OTHER_ROOM’ | List | User leaves, data id list |
functions 函数
static
functions | parameter | describe |
---|---|---|
TransformEx.MyPlayerTransform() | return:Transform | Get the transform of your own avatar |
TransformEx.PlayerTransform(userid) | 1.String return:Transform | Get the transform of other avatar by id |
TransformEx.GetAllPlayer() | return: List | Get the transform of all current players |
TransformEx.GetAllPlayerIds() | return: List | Get the ids of all current players |
TransformEx.MyPlayerID() | return:String | get your own id |
non-static
functions | parameter | describe |
---|---|---|
transform:MyPlayerTransform() | return:Transform | Get the transform of your own avatar |
transform:PlayerTransform(id) | 1. String return:Transform | Get the transform of other avatar by id |
transform:MyPlayerID() | return:String | Get the id of your own avatar |
transform:MyPlayerTransform() | return:Transform | Get the transform of your own avatar |
local rolels=newList(System.String) --创建String 数据列表,存储用户id
function Start()
rolels:AddRange(TransformEx.GetAllPlayerIds()) --获取当前所有用户id
print(rolels.Count)
logRoleids(rolels)
luaEvent:AddEventListener('MsgEventType.JOIN_OTHER_ROOM',this,onOtherPlayJoin)
luaEvent:AddEventListener('MsgEventType.OUT_OTHER_ROOM',this,onOtherPlayOut)
end
function onOtherPlayJoin(info)
if info:CheckData() then
local ls = info.Data
rolels:AddRange(ls)
logRoleids(ls)
end
end
function onOtherPlayOut(info)
if info:CheckData() then
local ls = info.Data
rolels:RemoveRange(ls)
logRoleids(ls)
end
end
function logRoleids(list)
for i = 0, list.Count-1 do
print('id',i,list[i])
end
print('current id')
end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
player animation
functions | parameter | describe |
---|---|---|
transform:PlayerState(AvatarV2StateType) | CS.AvatarV2StateType | Set the player animation state, if the transform is not the player, it will fail, |
transform:PlayerState() | return AvatarV2StateType | Get the player animation state, if the transform is not the player, it will fail, return id |
TransformEx.MyPlayerTransform():PlayerState(CS.AvatarV2StateType.Walk)
print(TransformEx.MyPlayerTransform():PlayerState())
1
2
2